package com.edu.exam.enums.assessment;

/**
 * 考核时机枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum AssessmentTiming {
    BEFORE_TERM("BEFORE_TERM", "课前"),
    DURING_TERM("DURING_TERM", "课中"),
    AFTER_TERM("AFTER_TERM", "课后"),
    MID_TERM("MID_TERM", "期中"),
    FINAL_TERM("FINAL_TERM", "期末"),
    WEEKLY("WEEKLY", "每周"),
    MONTHLY("MONTHLY", "每月"),
    IRREGULAR("IRREGULAR", "不定期");

    private final String code;
    private final String description;

    AssessmentTiming(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static AssessmentTiming fromCode(String code) {
        for (AssessmentTiming timing : AssessmentTiming.values()) {
            if (timing.code.equals(code)) {
                return timing;
            }
        }
        throw new IllegalArgumentException("Unknown assessment timing code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static AssessmentTiming fromDescription(String description) {
        for (AssessmentTiming timing : AssessmentTiming.values()) {
            if (timing.description.equals(description)) {
                return timing;
            }
        }
        throw new IllegalArgumentException("Unknown assessment timing description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}